﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EyFramework.ORM;
using Ncov2019.Entity;

namespace Ncov2019.Core.Dao
{
    public class NcovRegistDao : BaseDaoHis<NcovRegist>, INcovRegistDao
    {
        public List<NcovRegist> QueryRegistInfo(NcovInfoParam param)
        {
            string sql = @"SELECT SEQ,
                PATIENT_ID,
                PATIENT_NAME,
                BIRTHDAY,
                SEX,
                ID_TYPE,
                ID_NO,
                TELPHONE,
                COMPANY,
                CONTACT_NM,
                CONTACT_ID_NO,
                CONTACT_ID_TYPE,
                ADDRESS_PROVINCE,
                ADDRESS_CITY,
                ADDRESS_COUNTY,
                ADDRESS_TOWN,
                ADDRESS_OTHER,
                SFPH,
                JKM,
                ZGWDQ,
                JJXFR,
                XGQZHZ,
                SFFR,
                HXDZZ,
                TRYW,
                REGIST_DT,
                REGIST_DT_C,
                TEMPERATURE,
                (select listagg(b.keshimc, ',') within group( order by keshimc) as keshimc from  his6.zj_jiuzhenxx a,his6.gy_keshi b where a.jiuzhenks=b.keshiid and a.bingrenid=PATIENT_ID and TO_CHAR(REGIST_DT, 'YYYY-MM-DD')=TO_CHAR(a.jiuzhenrq, 'YYYY-MM-DD')) JIUZHENKS,
                BIRTHPLACE,ADDRESS_PROVINCE || ADDRESS_CITY || ADDRESS_COUNTY || ADDRESS_TOWN || ADDRESS_OTHER as ADDRESS FROM NCOV_REGIST WHERE 1=1 ";
            if (!string.IsNullOrEmpty(param.CHT_ID))
            {
                sql = sql + " and PATIENT_ID = '" + param.CHT_ID + "'";
            }

            if (!string.IsNullOrEmpty(param.PAT_NM))
            {
                sql = sql + " and PATIENT_NAME = '" + param.PAT_NM + "'";
            }
            if (!string.IsNullOrEmpty(param.START_DT))
            {
                sql = sql + " and REGIST_DT_C >= '" + param.START_DT + "'";
            }

            if (!string.IsNullOrEmpty(param.END_DT))
            {
                sql = sql + " and REGIST_DT_C <= '" + param.END_DT + "'";
            }

            return Db.Ado.SqlQuery<NcovRegist>(sql);
        }
    }
}